package Presentacion;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import java.util.Arrays;

import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;


public class Frame_user {

	private JFrame frmLogin;
	private final JLabel lblLogo = new JLabel("");
	private final JLabel lblUser = new JLabel("Usuario:");
	private final JLabel lblPass = new JLabel("Contraseña:");
	private final JTextField txtUser = new JTextField();
	private final JPanel panel = new JPanel();
	private final JPasswordField passwordField = new JPasswordField();
	private final JButton btnEntrar = new JButton("Entrar");
	private final JLabel lblV = new JLabel("V0.1");
	private final JLabel lblMAppS = new JLabel("MAppS - More Applications 2013©");
	private final JLabel lblNewLabel = new JLabel("");
	private final JLabel lblOKU = new JLabel("");
	private final JLabel lblOKC = new JLabel("");
	
	private static final char[] password = {'i', 'p', 'o'};
	private final JLabel label = new JLabel("");
	private final JLabel label_1 = new JLabel("");
	public static String usuario;
	private final JLabel lblMoreCalendar = new JLabel("More Calendar");

	
	public JFrame getFrmLogin() {
		return frmLogin;
	}
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Frame_user window = new Frame_user();
					window.frmLogin.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Frame_user() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmLogin = new JFrame();
		frmLogin.getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 11));
		frmLogin.setResizable(false);
		frmLogin.getContentPane().setBackground(SystemColor.textHighlightText);
		frmLogin.setTitle("More Calendar");
		frmLogin.setIconImage(Toolkit.getDefaultToolkit().getImage(Frame_user.class.getResource("/images/iconitos_004.jpg")));
		frmLogin.setBounds(400, 200, 509, 294);
		frmLogin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmLogin.getContentPane().setLayout(null);
		{
			panel.setBackground(Color.WHITE);
			panel.setBounds(0, 0, 503, 240);
			frmLogin.getContentPane().add(panel);
		}
		panel.setLayout(null);
		{
			lblLogo.setBounds(20, 39, 202, 163);
			panel.add(lblLogo);
			lblLogo.setIcon(new ImageIcon(Frame_user.class.getResource("/images/iconitos_004.jpg")));
		}
		lblUser.setFont(new Font("Verdana", Font.BOLD, 12));
		lblUser.setBounds(232, 103, 73, 14);
		panel.add(lblUser);
		lblPass.setEnabled(false);
		lblPass.setFont(new Font("Verdana", Font.BOLD, 12));
		lblPass.setBounds(232, 139, 89, 14);
		panel.add(lblPass);
		txtUser.addActionListener(new TxtUserActionListener());
		txtUser.setBounds(334, 101, 126, 20);
		panel.add(txtUser);
		txtUser.setColumns(10);
		passwordField.addActionListener(new PasswordFieldActionListener());
		passwordField.setEnabled(false);
		passwordField.setBounds(334, 137, 126, 20);
		
		panel.add(passwordField);
		{
			btnEntrar.addActionListener(new MiEntrarActionListener());
			btnEntrar.setEnabled(false);
			btnEntrar.setBounds(352, 193, 89, 23);
			panel.add(btnEntrar);
		}
		{
			lblMoreCalendar.setForeground(new Color(30, 144, 255));
			lblMoreCalendar.setFont(new Font("Microsoft Sans Serif", Font.BOLD, 34));
			lblMoreCalendar.setBounds(229, 25, 264, 47);
			panel.add(lblMoreCalendar);
		}
	
	
		{
			lblV.setForeground(Color.GRAY);
			lblV.setBounds(10, 244, 46, 14);
			frmLogin.getContentPane().add(lblV);
		}
		{
			lblMAppS.setForeground(Color.GRAY);
			lblMAppS.setBounds(309, 244, 194, 14);
			frmLogin.getContentPane().add(lblMAppS);
		}
	}
	private class TxtUserActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			lblPass.setEnabled(true);
			passwordField.setEnabled(true);
			lblUser.setEnabled(false);
			txtUser.setEnabled(false);
			btnEntrar.setEnabled(true);
			
		}
	}
	private class PasswordFieldActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			char [] passwordIntro=passwordField.getPassword();
			if (esPasswordCorrecta(passwordIntro))
					activarEntrar();
			else activarCorregir();
		}
	}
	private class MiEntrarActionListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {
			//usuario=txtUser.getText();
			//new Frame_user().getFrmLogin().setVisible(true);
			frmLogin.setVisible(false);
		}
	}
	
	private static boolean esPasswordCorrecta(char[] input){
		boolean esCorrecta=true;
		if (input.length != password.length)
			esCorrecta=false;
		else esCorrecta=Arrays.equals (input, password);
		return esCorrecta;
	}
	
	private static void activarEntrar(){
	
	}
	
	private static void activarCorregir(){
		
	}
}
